package com.gz.controller;

import com.gz.entity.Product;
import com.gz.service.ProductService;
import com.gz.vo.BaseRS;
import com.gz.vo.ProductLocVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiResponse;
import io.swagger.annotations.ApiResponses;
import java.lang.reflect.InvocationTargetException;
import java.util.List;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

@RestController
@Api(value = "商品controller", tags = "商品控制类", description = "商品控制类")
public class ProductController {

  @Autowired
  private ProductService productService;

  @GetMapping("/queryAllProducts")
  @ApiOperation(value = "查询所有商品", notes = "查询所有商品数据")
  @ApiResponses({
      @ApiResponse(code = 200, message = "OK", response = Product.class),
  })
  public BaseRS queryAllProducts() {
    return productService.queryAllProducts();
  }


  @RequestMapping(value = "/queryProductsByPrarm", method = RequestMethod.POST)
  @ApiOperation(value = "根据商品属性查询商品", notes = "根据商品属性查询商品")
  @ApiResponses({
      @ApiResponse(code = 200, message = "OK", response = Product.class),
  })
  public BaseRS queryProductsByPrarm(@RequestBody Product product, HttpServletRequest request,
      HttpServletResponse response) {
    return productService.queryProductsByPrarm(product);
  }

  @RequestMapping(value = "/queryProductsByExr", method = RequestMethod.POST)
  @ApiOperation(value = "根据商品属性查询商品", notes = "根据商品属性查询商品")
  @ApiResponses({
      @ApiResponse(code = 200, message = "OK", response = Product.class),
  })
  public BaseRS queryProductsByExr(@RequestBody ProductLocVo product, HttpServletRequest request,
      HttpServletResponse response) {
    return productService.queryProductsByPrarmExr(product);
  }

  @RequestMapping(value = "/queryProductsByType", method = RequestMethod.POST)
  @ApiOperation(value = "根据商品属性查询商品", notes = "根据商品属性查询商品")
  @ApiResponses({
      @ApiResponse(code = 200, message = "OK", response = Product.class),
  })
  public BaseRS queryProductsByType(@RequestBody ProductLocVo product, HttpServletRequest request,
      HttpServletResponse response) {
    return productService.queryProductsByType(product);
  }

  @RequestMapping(value = "/queryProductsByStore", method = RequestMethod.POST)
  @ApiOperation(value = "根据商品属性查询商品", notes = "根据商品属性查询商品")
  @ApiResponses({
      @ApiResponse(code = 200, message = "OK", response = Product.class),
  })
  public BaseRS queryProductsByStore(@RequestBody ProductLocVo product, HttpServletRequest request,
      HttpServletResponse response) throws InvocationTargetException, IllegalAccessException {
    return productService.queryProductsByStore(product);
  }

  @RequestMapping(value = "/queryById", method = RequestMethod.GET)
  @ApiOperation(value = "根据商品id查询商品", notes = "根据商品id查询商品")
  @ApiResponses({
      @ApiResponse(code = 200, message = "OK", response = Product.class),
  })
  public BaseRS queryProductById(@RequestParam(value = "id") Integer id) {
    BaseRS baseRS = productService.queryProductById(id);
    return baseRS;
  }

  @PostMapping("/saveProduct")
  @ApiOperation(value = "新增商品", notes = "新增商品")
  public BaseRS saveProduct(@RequestBody Product product, HttpServletRequest request,
      HttpServletResponse response) {
    return productService.saveProduct(product);
  }


  @PostMapping("/saveProducts")
  @ApiOperation(value = "批量新增商品", notes = "批量新增商品")
  public BaseRS saveProducts(@RequestBody List<Product> products, HttpServletRequest request,
      HttpServletResponse response) {
    return productService.saveProducts(products);
  }


  @PostMapping("/updateProduct")
  @ApiOperation(value = "更新商品", notes = "更新商品商品")
  public BaseRS updateProduct(@RequestBody Product product, HttpServletRequest request,
      HttpServletResponse response) {
    return productService.updateProduct(product);
  }

  @GetMapping("/deleteProduct")
  @ApiOperation(value = "删除商品", notes = "删除商品")
  public BaseRS deleteProduct(@RequestParam String productId) {
    return productService.delProduct(productId);
  }


}
